#include "mainwindow.h"
#include "qthread.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);    

    setWindowTitle("永联模块控制系统_V1.2");

    //创建线程对象
    QThread* task2 = new QThread;               //task2:CAN操作
    //创建任务对象
    canThread* can = new canThread;
    //放入多线程
    can->moveToThread(task2);
    //启动线程
    task2->start();

    thread_1 = new QThread;
    recharge = new RechargeThread;
    recharge->moveToThread(thread_1);
    thread_1->start();

    InitView();
    LightInit();
    customPlotModule_V_A();

    QStringList strList1;
    strList1<<"20KW模块"<<"40KW模块";
    //ui->comboBox_all->addItems(strList1);

    QStringList strList2;
    strList2<<"交流模式"<<"直流模式";


    refreshTimer = startTimer(100, Qt::CoarseTimer);
    sampleTimer = startTimer(100, Qt::CoarseTimer);

    connect(this,&MainWindow::SIGtocancon,can,&canThread::openCan);  //点击启动CAN按钮打开CAN
    connect(this,&MainWindow::SIGtocansto,can,&canThread::stopCan);  //点击启动CAN按钮打开CAN
    connect(this,&MainWindow::SIGtocansen,can,&canThread::sendData); //点击发送按钮将框内ID和Data数据送到CAN发送函数
    connect(can,&canThread::SIGcanclosuc,this,&MainWindow::SignalCAN_start);
    connect(can,&canThread::SIGcanopefai,this,&MainWindow::SignalCAN_stop);
    connect(can,&canThread::dataCan,recharge,&RechargeThread::data);
    connect(can,&canThread::dataCan1,recharge,&RechargeThread::data1);
    connect(can,&canThread::dataCan2,recharge,&RechargeThread::data2);
    connect(can,&canThread::dataCan3,recharge,&RechargeThread::data3);
    connect(recharge,&RechargeThread::sig_module1_V,this,&MainWindow::modView_V1);
    connect(recharge,&RechargeThread::sig_module1_A,this,&MainWindow::modView_A1);
    connect(recharge,&RechargeThread::sig_module1_mol,this,&MainWindow::modView_mod1);
    connect(recharge,&RechargeThread::sig_module1_limit,this,&MainWindow::modView_lim1);
    connect(recharge,&RechargeThread::sig_module1_tem,this,&MainWindow::modView_tem1);
    connect(recharge,&RechargeThread::sig_module1_w,this,&MainWindow::modView_w1);
    connect(recharge,&RechargeThread::sig_module1_state,this,&MainWindow::modView_state1);
    connect(recharge,&RechargeThread::sig_module2_V,this,&MainWindow::modView_V2);
    connect(recharge,&RechargeThread::sig_module2_A,this,&MainWindow::modView_A2);
    connect(recharge,&RechargeThread::sig_module2_mol,this,&MainWindow::modView_mod2);
    connect(recharge,&RechargeThread::sig_module2_limit,this,&MainWindow::modView_lim2);
    connect(recharge,&RechargeThread::sig_module2_tem,this,&MainWindow::modView_tem2);
    connect(recharge,&RechargeThread::sig_module2_w,this,&MainWindow::modView_w2);
    connect(recharge,&RechargeThread::sig_module2_state,this,&MainWindow::modView_state2);
    connect(recharge,&RechargeThread::sig_module3_V,this,&MainWindow::modView_V3);
    connect(recharge,&RechargeThread::sig_module3_A,this,&MainWindow::modView_A3);
    connect(recharge,&RechargeThread::sig_module3_mol,this,&MainWindow::modView_mod3);
    connect(recharge,&RechargeThread::sig_module3_limit,this,&MainWindow::modView_lim3);
    connect(recharge,&RechargeThread::sig_module3_tem,this,&MainWindow::modView_tem3);
    connect(recharge,&RechargeThread::sig_module3_w,this,&MainWindow::modView_w3);
    connect(recharge,&RechargeThread::sig_module3_state,this,&MainWindow::modView_state3);
    connect(recharge,&RechargeThread::sig_module4_V,this,&MainWindow::modView_V4);
    connect(recharge,&RechargeThread::sig_module4_A,this,&MainWindow::modView_A4);
    connect(recharge,&RechargeThread::sig_module4_mol,this,&MainWindow::modView_mod4);
    connect(recharge,&RechargeThread::sig_module4_limit,this,&MainWindow::modView_lim4);
    connect(recharge,&RechargeThread::sig_module4_tem,this,&MainWindow::modView_tem4);
    connect(recharge,&RechargeThread::sig_module4_w,this,&MainWindow::modView_w4);
    connect(recharge,&RechargeThread::sig_module4_state,this,&MainWindow::modView_state4);
    connect(this,&MainWindow::Bug_SCI,this,&MainWindow::BugView_SCI);
    connect(this,&MainWindow::Bug_JX,this,&MainWindow::BugView_JX);
    connect(this,&MainWindow::Bug_ModBug,this,&MainWindow::BugView_ModBug);
    connect(this,&MainWindow::Bug_DCGY,this,&MainWindow::BugView_DCGY);
    connect(this,&MainWindow::Bug_PFC,this,&MainWindow::BugView_PFC);
    connect(this,&MainWindow::Bug_JLGY,this,&MainWindow::BugView_JLGY);
    connect(this,&MainWindow::Bug_JLQY,this,&MainWindow::BugView_JLQY);
    connect(this,&MainWindow::Bug_CAN,this,&MainWindow::BugView_CAN);
    connect(this,&MainWindow::Bug_BJL,this,&MainWindow::BugView_BJL);
    connect(this,&MainWindow::Bug_FS,this,&MainWindow::BugView_FS);
    connect(this,&MainWindow::Bug_DCDL,this,&MainWindow::BugView_DCDL);
    connect(this,&MainWindow::Bug_DCGW,this,&MainWindow::BugView_DCGW);
    connect(this,&MainWindow::Bug_DCSCGY,this,&MainWindow::BugView_DCSCGY);
    //connect(can,&canThread::SendCan,ui->textEdit,&QTextEdit::append);  //显示CAN接收数据

    timer1.setTimerType(Qt::PreciseTimer);
    connect(&timer1,&QTimer::timeout,this,[=]()
    {
        Visitstate1();//访问模块状态
        Visitstate2();
        Visitstate3();
        Visitstate4();

        VisitV1();//访问电压状态
        VisitV2();
        VisitV3();
        VisitV4();

        VisitA1();//访问电流状态
        VisitA2();
        VisitA3();
        VisitA4();

        VisitTem1();//访问模块温度
        VisitTem2();
        VisitTem3();
        VisitTem4();

        VisitLimit1();//访问模块限流点
        VisitLimit2();
        VisitLimit3();
        VisitLimit4();

        Visitmol1();//访问模块工作模式
        Visitmol2();
        Visitmol3();
        Visitmol4();

        VisitW1();//访问额定功率
        VisitW2();
        VisitW3();
        VisitW4();

        Setmodule();
    });
    timer1.start(100);

    //on_btnCan_clicked();
    on_btnCAN_clicked();
//    QString data = "442F0000";
//    uint vol = data.toUInt(nullptr, 16);
//    V1 = *(float*)&vol;
//    qDebug()<<V1;
}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::InitView()
{    
    //createIndicatorLabel(ui->label_3,7,80,"交流过压",1);

    ui->btn_res_3->setStyleSheet("QPushButton{background-color:#ffaa00;"//背景红色
                               "border-radius: 10px;}"
                               "QPushButton:hover{"
                               "background-color:#ffaa7f;"
                               "color:white;"
                               "}");
    ui->btn_res_2->setStyleSheet("QPushButton{background-color:#ffaa00;"//背景红色
                               "border-radius: 10px;}"
                               "QPushButton:hover{"
                               "background-color:#ffaa7f;"
                               "color:white;"
                               "}");
    ui->btn_setA_2->setStyleSheet("QPushButton{background-color:rgb(20,196,188);"//背景蓝色
                               "border-radius: 10px;}"
                               "QPushButton:hover{"
                               "background-color:#40E0D0;"
                               "color:white;"
                               "}");
    ui->lineEdit_setV->setStyleSheet("font: 25 16pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:20px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:2px solid rgb(20,196,188);border-radius:0px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_setV_2->setStyleSheet("font: 25 16pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:30px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:2px solid rgb(20,196,188);border-radius:0px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_setA->setStyleSheet("font: 25 16pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:20px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:2px solid rgb(20,196,188);border-radius:0px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_setA_2->setStyleSheet("font: 25 16pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:30px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:2px solid rgb(20,196,188);border-radius:0px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol1->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:15px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol1_2->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:15px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol2->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:15px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol2_2->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:15px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol3->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:15px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol4->setStyleSheet("font: 25 12pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:15px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(128,138,135);border-radius:3px;");//边框粗细-颜色-圆角设置
    ui->lineEdit_mol->setStyleSheet("font: 50 20pt '微软雅黑 Light';" //字体
                            "color: rgb(31,31,31);"		//字体颜色
                            "padding-left:20px;"       //内边距-字体缩进
                            "background-color: rgb(255, 255, 255);" //背景颜色
                            "border:3px solid rgb(20,196,188);border-radius:5px;");//边框粗细-颜色-圆角设置

    ui->lineEdit_mol1->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_mol1->setReadOnly(true);
    ui->lineEdit_mol2->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_mol2->setReadOnly(true);
    ui->lineEdit_mol3->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_mol3->setReadOnly(true);
    ui->lineEdit_mol4->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_mol4->setReadOnly(true);
    ui->lineEdit_mol->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_mol->setReadOnly(true);

    ui->lineEdit_V1->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_V1->setReadOnly(true);
    ui->lineEdit_V2->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_V2->setReadOnly(true);
    ui->lineEdit_V3->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_V3->setReadOnly(true);
    ui->lineEdit_V4->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_V4->setReadOnly(true);

    ui->lineEdit_A1->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_A1->setReadOnly(true);
    ui->lineEdit_A2->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_A2->setReadOnly(true);
    ui->lineEdit_A3->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_A3->setReadOnly(true);
    ui->lineEdit_A4->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_A4->setReadOnly(true);

    ui->lineEdit_lim1->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_lim1->setReadOnly(true);
    ui->lineEdit_lim2->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_lim2->setReadOnly(true);
    ui->lineEdit_lim3->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_lim3->setReadOnly(true);
    ui->lineEdit_lim4->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_lim4->setReadOnly(true);

    ui->lineEdit_tem1->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_tem1->setReadOnly(true);
    ui->lineEdit_tem2->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_tem2->setReadOnly(true);
    ui->lineEdit_tem3->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_tem3->setReadOnly(true);
    ui->lineEdit_tem4->setFocusPolicy(Qt::ClickFocus);
    ui->lineEdit_tem4->setReadOnly(true);
}

void MainWindow::LightInit()
{
    ui->lightButton_TX->setGray();

    ui->light_start1->setGray();
    ui->light_start2->setGray();
    ui->light_start3->setGray();
    ui->light_start4->setGray();
    ui->light_bug1->setGray();
    ui->light_bug2->setGray();
    ui->light_bug3->setGray();
    ui->light_bug4->setGray();
    ui->light_pro1->setGray();
    ui->light_pro2->setGray();
    ui->light_pro3->setGray();
    ui->light_pro4->setGray();
    ui->light_w1->setGray();
    ui->light_w2->setGray();
    ui->light_w3->setGray();
    ui->light_w4->setGray();
    ui->light_cur1->setGray();
    ui->light_cur2->setGray();
    ui->light_cur3->setGray();
    ui->light_cur4->setGray();
    ui->light_tem1->setGray();
    ui->light_tem2->setGray();
    ui->light_tem3->setGray();
    ui->light_tem4->setGray();
}

/*封装label，设置label大小，颜色，内部字体，颜色，内容，并根据需要是否显示内部字体，使其成为一个指示灯*/
void MainWindow::createIndicatorLabel(QLabel *label, int color, int size, QString number, bool numlock)
{
    /*label->传入的label，color->颜色标识，size->指示灯大小，
      number->需要显示的数字，numlock->是否需要显示数字*/
    label->setFixedSize(size,size);//设置固定大小，为圆形label准备
    label->setText("");//清除文本
    label->setStyleSheet("");//清除样式表
    QString htmlText, styleSheet, labelcolor;
    /*
        根据传入的color标识，确定为指示灯显示何种颜色
        1--黑色，2--蓝色，3--绿色，4--紫色，5--红色，6-黄色
        */
    if(color == 1)
    {
        labelcolor = QColor(Qt::black).name();//1--黑色
    }
    else if(color == 2)
    {
        labelcolor = QColor(Qt::blue).name();//2--蓝色
    }
    else if(color == 3)
    {
        labelcolor = QColor(Qt::green).name();//3--绿色
    }
    else if(color == 4)
    {
        labelcolor = QColor(Qt::darkMagenta).name();//4--紫色
    }
    else if(color == 5)
    {
        labelcolor = QColor(Qt::red).name();//5--红色
    }
    else if(color == 6)
    {
        labelcolor = QColor(Qt::yellow).name();//黄色
    }
    else if(color == 7)
    {
        labelcolor = QColor(Qt::gray).name();//灰色
    }
    /*根据numlock确认是否需要显示内部数字*/
    if(numlock)
    {
        /*样式表设置label格式，背景颜色labelcolor;边框半径size/2;字体颜色：黄色，居中显示;2px宽度黄色实线边框*/
        styleSheet = QString("background-color: %1; border-radius: %2; color: %3; text-align: center; border: 0px solid gray; padding: 12px;")
                .arg(labelcolor)
                .arg(size/2)
                .arg(QColor(Qt::black).name());
        /*HTML格式设置字体，字体样式"Times New Roman";字体大小18;显示的内容number*/
        htmlText = QString("<html><body><div style = \"font-family: %1; font-size: %2px; \">%3</div></body></html>")
                .arg("Times New Roman")
                .arg(10)
                .arg(number);
    }
    else
    {
        styleSheet = QString("background-color: %1; border-radius: %2; color: %3; text-align: center; border: 1px solid yellow; padding: 2px;")
                .arg(labelcolor)
                .arg(size/2)
                .arg(QColor(Qt::yellow).name());
    }
    label->setStyleSheet(styleSheet);//设置样式表
    label->setText(htmlText);//设置文本

}

void MainWindow::timerEvent(QTimerEvent *event)
{
    Q_UNUSED(event);
    double key = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0;

    if(event->timerId() == refreshTimer)
    {
        double xHigh = key - 0.5;
        plot->xAxis->setRange(xHigh - plot->xAxis->range().size(),xHigh);
        plot->replot();

    }

    if(event->timerId() == sampleTimer) //30ms
    {
        plot->graph(0)->addData(key, V1);
        plot->graph(1)->addData(key, V2);
        plot->graph(2)->addData(key, V3);
        plot->graph(3)->addData(key, V4);

        plot->graph(4)->addData(key, A1);
        plot->graph(5)->addData(key, A2);
        plot->graph(6)->addData(key, A3);
        plot->graph(7)->addData(key, A4);

        //ui->lineEdit_system_A->setText(QString::number(sys_cur)+"A");
        //ui->lineEdit_system_V->setText(QString::number(sys_vol)+"V");

//        ui->lineEdit_module1_A->setText(QString::number(V1)+"A");
//        ui->lineEdit_module1_V->setText(QString::number(A1)+"V");

//        ui->lineEdit_module2_A->setText(QString::number(V2)+"A");
//        ui->lineEdit_module2_V->setText(QString::number(A2)+"V");

//        ui->lineEdit_module3_A->setText(QString::number(V3)+"A");
//        ui->lineEdit_module3_V->setText(QString::number(A3)+"V");

//        ui->lineEdit_module4_A->setText(QString::number(V4)+"A");
//        ui->lineEdit_module4_V->setText(QString::number(A4)+"V");
    }
    plot->graph(0)->removeDataBefore(key - 5000);
    plot->graph(1)->removeDataBefore(key - 5000);
    plot->graph(2)->removeDataBefore(key - 5000);
    plot->graph(3)->removeDataBefore(key - 5000);

    plot->graph(4)->removeDataBefore(key - 5000);
    plot->graph(5)->removeDataBefore(key - 5000);
    plot->graph(6)->removeDataBefore(key - 5000);
    plot->graph(7)->removeDataBefore(key - 5000);
}

void MainWindow::customPlotModule_V_A()
{
    plot = ui->Plot;

    //渐变背景颜色
    QLinearGradient gradient(0, 0, 0, 400);
    gradient.setColorAt(0, QColor(90, 90, 90));
    gradient.setColorAt(0.38, QColor(105, 105, 105));
    gradient.setColorAt(1, QColor(70, 70, 70));
    plot->setBackground(QBrush(gradient));

    //添加图的title
    QCPTextElement *title_txt = new QCPTextElement(plot,"模块电压/电流曲线", QFont("sans", 12, QFont::Bold));
    title_txt->setTextColor(Qt::white);  //修改颜色
    plot->plotLayout()->insertRow(0);
    plot->plotLayout()->addElement(0, 0, title_txt);

    //日期做X轴
    QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
    dateTicker->setDateTimeFormat("hh:mm:ss"); //日期格式
    plot->xAxis->setTicker(dateTicker); //设置X轴为时间轴

    connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));

    plot->setInteractions(QCP::iRangeDrag
                          |QCP::iRangeZoom
                          |QCP::iSelectLegend
                          |QCP::iSelectAxes
                          |QCP::iSelectPlottables);
    plot->axisRect()->setRangeZoomFactor(1.2,1);//x方向为1.2 y为1 是不改变。

    //坐标轴设置
    QFont font;
    font.setPixelSize(18);
    plot->xAxis->setLabel("时间【时:分:秒】");
    plot->xAxis->setTickLabels(true); //显示刻度标签
    //plot->xAxis->setLabelFont(font);
    plot->yAxis->setRange(0, 1000);
    plot->yAxis->setLabel("电压(V)");
    plot->yAxis->setLabelFont(font);
    plot->yAxis2->setLabel("电流(A)");
    plot->yAxis2->setLabelFont(font);
    plot->yAxis2->setVisible(true);
    plot->yAxis2->setRange(0, 100);  //当前Y_2轴显示的范围

    plot->xAxis->setBasePen(QPen(Qt::white,1));//设置x轴坐标轴颜色
    plot->yAxis->setBasePen(QPen(Qt::white,1));//设置y轴坐标轴颜色
    plot->yAxis2->setBasePen(QPen(Qt::white,1));//设置y轴坐标轴颜色
    plot->xAxis->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
    plot->yAxis->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
    plot->yAxis2->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
    plot->xAxis->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
    plot->yAxis->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
    plot->yAxis2->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
    plot->xAxis->setTickLabelColor(Qt::white);//设置x轴坐标颜色
    plot->yAxis->setTickLabelColor(Qt::white);//设置y轴坐标颜色
    plot->yAxis2->setTickLabelColor(Qt::white);//设置y轴坐标颜色
    plot->xAxis->setLabelColor(Qt::white);//设置x轴名称颜色
    plot->yAxis->setLabelColor(Qt::white);//设置y轴名称颜色
    plot->yAxis2->setLabelColor(Qt::white);//设置y轴名称颜色

    //设置图例属性
    plot->xAxis->grid()->setPen(QPen(QColor(180, 180, 180), 1, Qt::PenStyle::DashLine));//网格白色虚线
    plot->yAxis->grid()->setPen(QPen(QColor(180, 180, 180), 1, Qt::PenStyle::DashLine));//网格白色虚线
    plot->xAxis->grid()->setSubGridPen(QPen(QColor(50, 50, 50), 1, Qt::DotLine));//网格浅色点线
    plot->yAxis->grid()->setSubGridPen(QPen(QColor(50, 50, 50), 1, Qt::DotLine));//网格浅色点线
    //plot->xAxis->grid()->setSubGridVisible(true);//显示x轴子网格线
    //plot->yAxis->grid()->setSubGridVisible(true);//显示要轴子网格线
    plot->xAxis->grid()->setZeroLinePen(QPen(Qt::white));//x轴0线颜色白色
    plot->yAxis->grid()->setZeroLinePen(QPen(Qt::white));//y轴0线颜色白色


    //电压曲线
    plot->addGraph(plot->xAxis,plot->yAxis);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis);
    plot->addGraph(plot->xAxis,plot->yAxis);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis);

    //电流曲线
    plot->addGraph(plot->xAxis,plot->yAxis2);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis2);
    plot->addGraph(plot->xAxis,plot->yAxis2);                              //向绘图区域QCustomPlot添加一条曲线
    plot->addGraph(plot->xAxis,plot->yAxis2);

//    //曲线颜色
//    plot->graph(0)->setPen(QPen(QColor("#0066FF")));                //绘制曲线0的画刷颜色为红色
//    plot->graph(1)->setPen(QPen(QColor("#6A5ACD")));              //绘制曲线1的画刷颜色为蓝色
//    plot->graph(2)->setPen(QPen(QColor("#00FFFF")));                //绘制曲线0的画刷颜色为红色
//    plot->graph(3)->setPen(QPen(QColor("#CC00FF")));

//    plot->graph(4)->setPen(QPen(QColor("#2E8B57")));
//    plot->graph(5)->setPen(QPen(QColor("#77FF00")));
//    plot->graph(6)->setPen(QPen(QColor("#00C78C")));
//    plot->graph(7)->setPen(QPen(QColor("#BDFCC9")));

    QPen pen;
    pen.setWidth(3);//设置线宽
    pen.setColor(Qt::blue);
    QPen pen1;
    pen1.setWidth(3);//设置线宽
    pen1.setColor(Qt::cyan);
    QPen pen2;
    pen2.setWidth(3);//设置线宽
    pen2.setColor(Qt::magenta);
    QPen pen3;
    pen3.setWidth(3);//设置线宽
    pen3.setColor(Qt::darkBlue);
    QPen pen4;
    pen4.setWidth(3);//设置线宽
    pen4.setColor(Qt::green);
    QPen pen5;
    pen5.setWidth(3);//设置线宽
    pen5.setColor(Qt::yellow);
    QPen pen6;
    pen6.setWidth(3);//设置线宽
    pen6.setColor(Qt::darkGreen);
    QPen pen7;
    pen7.setWidth(3);//设置线宽
    pen7.setColor(Qt::darkYellow);
    plot->graph(0)->setPen(pen);
    plot->graph(1)->setPen(pen1);
    plot->graph(2)->setPen(pen2);
    plot->graph(3)->setPen(pen3);
    plot->graph(4)->setPen(pen4);
    plot->graph(5)->setPen(pen5);
    plot->graph(6)->setPen(pen6);
    plot->graph(7)->setPen(pen7);

    //图例显示
    plot->legend->setVisible(true);
    plot->graph(0)->setName("电压1");
    plot->graph(1)->setName("电压2");
    plot->graph(2)->setName("电压3");
    plot->graph(3)->setName("电压4");

    plot->graph(4)->setName("电流1");
    plot->graph(5)->setName("电流2");
    plot->graph(6)->setName("电流3");
    plot->graph(7)->setName("电流4");

    //图例选中图像信号槽连接
    connect(ui->Plot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
//    ui->plot->setInteractions(QCP::iSelectLegend | QCP::iSelectPlottables);
//    ui->plot->legend->setSelectableParts(QCPLegend::spItems);


    //图像自适应坐标轴
    plot->graph(0)->rescaleAxes();
    plot->graph(1)->rescaleAxes();
    plot->graph(2)->rescaleAxes();
    plot->graph(3)->rescaleAxes();
    plot->graph(4)->rescaleAxes();
    plot->graph(5)->rescaleAxes();
    plot->graph(6)->rescaleAxes();
    plot->graph(7)->rescaleAxes();

    plot->legend->setBrush(QBrush(Qt::transparent));     //设置图例透明无边框
    //plot_2->legend->setBorderPen(Qt::NoPen);//图例边框隐藏
    //plot_2->legend->setFont(QFont("sans", 16, QFont::Bold));
    plot->legend->setBorderPen(Qt::NoPen);
    plot->legend->setVisible(true);//设置曲线名称可见
    plot->legend->setTextColor(Qt::white);//black

    //游标初始化定义
    tracer = new QCPItemTracer(plot);
    //tracer->setInterpolating(false);
    tracer->setStyle(QCPItemTracer::tsCircle);
    tracer->setPen(QPen(Qt::red));
    tracer->setBrush(Qt::red);
    tracer->setSize(6);

    connect(plot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoveEvent(QMouseEvent*)));
    //connect(plot, SIGNAL(legendDoubleClick(QCPLegend*, QCPAbstractLegendItem*, QMouseEvent*)), this, SLOT(when_legendDoubleClick(QCPLegend*, QCPAbstractLegendItem*, QMouseEvent*)));

    //框选放大功能
//    plot->selectionRect()->setPen(QPen(Qt::black,1,Qt::DashLine));//设置选框的样式：虚线
//    plot->selectionRect()->setBrush(QBrush(QColor(0,0,100,50)));//设置选框的样式：半透明浅蓝
//    plot->setSelectionRectMode(QCP::SelectionRectMode::srmZoom);

    //设置鼠标放于绘图区，变为手型
    plot->setCursor(QCursor(Qt::PointingHandCursor));
}


void MainWindow::SignalCAN_start()
{
    ui->lightButton_TX->setLightBlue();
}

void MainWindow::SignalCAN_stop()
{
    ui->lightButton_TX->setGray();
}

void MainWindow::SignalCAN_receive()
{
    ui->lightButton_TX->setGreen();
}

void MainWindow::Setmodule()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300001F00000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitstate1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000004000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitstate2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000004000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitstate3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000004000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitstate4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000004000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::VisitV1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000000100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitV2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000000100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitV3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000000100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitV4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000000100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::VisitA1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000000200000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitA2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000000200000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitA3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000000200000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitA4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000000200000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitTem1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000001000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitTem2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000001000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitTem3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000001000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitTem4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000001000000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitLimit1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000000300000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitLimit2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000000300000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitLimit3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000000300000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitLimit4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000000300000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitmol1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000004B00000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitmol2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000004B00000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitmol3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000004B00000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::Visitmol4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000004B00000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitW1()
{
    int ID;
    ID = 0x06080780;
    QString Data = "1000001100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitW2()
{
    int ID;
    ID = 0x06080F80;
    QString Data = "1000001100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitW3()
{
    int ID;
    ID = 0x06081780;
    QString Data = "1000001100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::VisitW4()
{
    int ID;
    ID = 0x06081F80;
    QString Data = "1000001100000000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

void MainWindow::modView_V1(QString da)
{
    //QString data = "442F0000";
    uint vol = da.toUInt(nullptr, 16);
    V1 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_V1->setText(QString::number(V1,'f', 2)+"V");
}

void MainWindow::modView_V2(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    V2 = *(float*)&vol;
    //qDebug()<<V2;
    ui->lineEdit_V2->setText(QString::number(V2,'f', 2)+"V");
}

void MainWindow::modView_V3(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    V3 = *(float*)&vol;
    //qDebug()<<V3;
    ui->lineEdit_V3->setText(QString::number(V3,'f', 2)+"V");
}

void MainWindow::modView_V4(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    V4 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_V4->setText(QString::number(V4,'f', 2)+"V");
}

void MainWindow::modView_A1(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    A1 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_A1->setText(QString::number(A1,'f', 2)+"A");
}

void MainWindow::modView_A2(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    A2 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_A2->setText(QString::number(A2,'f', 2)+"A");
}

void MainWindow::modView_A3(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    A3 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_A3->setText(QString::number(A3,'f', 2)+"A");
}

void MainWindow::modView_A4(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    A4 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_A4->setText(QString::number(A4,'f', 2)+"A");
}

void MainWindow::modView_mod1(QString da)
{
    if(da == "00000001")
    {
        ui->lineEdit_mol1->setText("单向交流");
    }
    else if(da == "00000002")
    {
        ui->lineEdit_mol1->setText("直流");
    }
    else if(da == "00000003")
    {
        ui->lineEdit_mol1->setText("三相交流");
    }
    else if(da == "00000004")
    {
        ui->lineEdit_mol1->setText("相序错误");
    }
}

void MainWindow::modView_mod2(QString da)
{
    if(da == "00000001")
    {
        ui->lineEdit_mol2->setText("单向交流");
    }
    else if(da == "00000002")
    {
        ui->lineEdit_mol2->setText("直流");
    }
    else if(da == "00000003")
    {
        ui->lineEdit_mol2->setText("三相交流");
    }
    else if(da == "00000004")
    {
        ui->lineEdit_mol2->setText("相序错误");
    }
}

void MainWindow::modView_mod3(QString da)
{
    if(da == "00000001")
    {
        ui->lineEdit_mol3->setText("单向交流");
    }
    else if(da == "00000002")
    {
        ui->lineEdit_mol3->setText("直流");
    }
    else if(da == "00000003")
    {
        ui->lineEdit_mol3->setText("三相交流");
    }
    else if(da == "00000004")
    {
        ui->lineEdit_mol3->setText("相序错误");
    }
}

void MainWindow::modView_mod4(QString da)
{
    if(da == "00000001")
    {
        ui->lineEdit_mol4->setText("单向交流");
    }
    else if(da == "00000002")
    {
        ui->lineEdit_mol4->setText("直流");
    }
    else if(da == "00000003")
    {
        ui->lineEdit_mol4->setText("三相交流");
    }
    else if(da == "00000004")
    {
        ui->lineEdit_mol4->setText("相序错误");
    }
}

void MainWindow::modView_lim1(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    lim1 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_lim1->setText(QString::number(lim1*100,'f',0)+"%");
}

void MainWindow::modView_lim2(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    lim2 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_lim2->setText(QString::number(lim2*100,'f',0)+"%");
}

void MainWindow::modView_lim3(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    lim3 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_lim3->setText(QString::number(lim3*100,'f',0)+"%");
}

void MainWindow::modView_lim4(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    lim4 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_lim4->setText(QString::number(lim4*100,'f',0)+"%");
}

void MainWindow::modView_tem1(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    tem1 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_tem1->setText(QString::number(tem1)+"℃");
}

void MainWindow::modView_tem2(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    tem2 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_tem2->setText(QString::number(tem2)+"℃");
}

void MainWindow::modView_tem3(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    tem3 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_tem3->setText(QString::number(tem3)+"℃");
}

void MainWindow::modView_tem4(QString da)
{
    uint vol = da.toUInt(nullptr, 16);
    tem4 = *(float*)&vol;
    //qDebug()<<V1;
    ui->lineEdit_tem4->setText(QString::number(tem4)+"℃");
}

void MainWindow::modView_state1(QString da)
{
    QString byte1 = QString("%1").arg(da.mid(0,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte1_0 = byte1.mid(0,1);//模块故障（红指示灯）
    QString byte1_1 = byte1.mid(1,1);//模块保护（黄指示灯）
    //QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//模块内部 SCI 通信故障
    QString byte1_4 = byte1.mid(4,1);//输入模式检测错误（或输入接线错误）
    QString byte1_5 = byte1.mid(5,1);//监控下发输入模式与实际工作模式不匹配
    //QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//DCDC 过压
    if(byte1_0 == "0"){
        ui->light_bug1->setGreen();
    }else if(byte1_0 == "1"){
        ui->light_bug1->setRed();
    }
    if(byte1_1 == "0"){
        ui->light_pro1->setGreen();
    }else if(byte1_1 == "1"){
        ui->light_pro1->setYellow();
    }
    if(byte1_3 == "0"){
        bug1_SCI = 0;
    }else if(byte1_3 == "1"){
        bug1_SCI = 1;
    }
    if(byte1_4 == "0"){
        bug1_JX = 0;
    }else if(byte1_4 == "1"){
        bug1_JX = 1;
    }
    if(byte1_5 == "0"){
        bug1_ModBug = 0;
    }else if(byte1_5 == "1"){
        bug1_ModBug = 1;
    }
    if(byte1_7 == "0"){
        bug1_DCGY = 0;
    }else if(byte1_7 == "1"){
        bug1_DCGY = 1;
    }
    emit Bug_SCI(bug1_SCI+bug2_SCI+bug3_SCI+bug4_SCI);
    emit Bug_JX(bug1_JX+bug2_JX+bug3_JX+bug4_JX);
    emit Bug_ModBug(bug1_ModBug+bug2_ModBug+bug3_ModBug+bug4_ModBug);
    emit Bug_DCGY(bug1_DCGY+bug2_DCGY+bug3_DCGY+bug4_DCGY);

    QString byte2 = QString("%1").arg(da.mid(2,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte2_0 = byte2.mid(0,1);//PFC电压异常（不平衡或过压或欠压）
    QString byte2_1 = byte2.mid(1,1);//交流过压
    //QString byte2_2 = byte2.mid(2,1);//输出过压告警
    //QString byte2_3 = byte2.mid(3,1);//过温告警
    //QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    //QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//交流欠压
    //QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态
    if(byte2_0 == "0"){
        bug1_PFC = 0;
    }else if(byte2_0 == "1"){
        bug1_PFC = 1;
    }
    if(byte2_1 == "0"){
        bug1_JLGY = 0;
    }else if(byte2_1 == "1"){
        bug1_JLGY = 1;
    }
    if(byte2_6 == "0"){
        bug1_JLQY = 0;
    }else if(byte2_6 == "1"){
        bug1_JLQY = 1;
    }
    emit Bug_PFC(bug1_PFC+bug2_PFC+bug3_PFC+bug4_PFC);
    emit Bug_JLGY(bug1_JLGY+bug2_JLGY+bug3_JLGY+bug4_JLGY);
    emit Bug_JLQY(bug1_JLQY+bug2_JLQY+bug3_JLQY+bug4_JLQY);

    QString byte3 = QString("%1").arg(da.mid(4,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte3_0 = byte3.mid(0,1);//CAN通信故障
    QString byte3_1 = byte3.mid(1,1);//模块不均流
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    //QString byte3_3 = byte3.mid(3,1);//模块休眠
    //QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    //QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_6 = byte3.mid(5,1);//DCDC开关机状态 0：开机，1：关机
    QString byte3_7 = byte3.mid(7,1);//模块限功率
    if(byte3_0 == "0"){
        bug1_CAN = 0;
    }else if(byte3_0 == "1"){
        bug1_CAN = 1;
    }
    if(byte3_1 == "0"){
        bug1_BJL = 0;
    }else if(byte3_1 == "1"){
        bug1_BJL = 1;
    }
    if(byte3_6 == "0"){
        ui->light_start1->setGreen();
    }else if(byte3_6 == "1"){
        ui->light_start1->setRed();
    }
    if(byte3_7 == "0"){
        ui->light_w1->setGray();
    }else if(byte3_7 == "1"){
        ui->light_w1->setYellow();
    }
    emit Bug_CAN(bug1_CAN+bug2_CAN+bug3_CAN+bug4_CAN);
    emit Bug_BJL(bug1_BJL+bug2_BJL+bug3_BJL+bug4_BJL);

    QString byte4 = QString("%1").arg(da.mid(6,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte4_0 = byte3.mid(0,1);//温度限功率
    QString byte4_1 = byte3.mid(1,1);//交流限功率
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte4_3 = byte3.mid(3,1);//风扇故障
    QString byte4_4 = byte3.mid(4,1);//DCDC短路
    //QString byte4_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte4_6 = byte3.mid(5,1);//DCDC过温
    QString byte4_7 = byte3.mid(7,1);//DCDC输出过压
    if(byte4_0 == "0"){
        ui->light_tem1->setGray();
    }else if(byte4_0 == "1"){
        ui->light_tem1->setYellow();
    }
    if(byte4_1 == "0"){
        ui->light_cur1->setGray();
    }else if(byte4_1 == "1"){
        ui->light_cur1->setYellow();
    }
    if(byte4_3 == "0"){
        bug1_FS = 0;
    }else if(byte4_3 == "1"){
        bug1_FS = 1;
    }
    if(byte4_4 == "0"){
        bug1_DCDL = 0;
    }else if(byte4_4 == "1"){
        bug1_DCDL = 1;
    }
    if(byte4_6 == "0"){
        bug1_DCGW = 0;
    }else if(byte4_6 == "1"){
        bug1_DCGW = 1;
    }
    if(byte4_7 == "0"){
        bug1_DCSCGY = 0;
    }else if(byte4_7 == "1"){
        bug1_DCSCGY = 1;
    }
    emit Bug_FS(bug1_FS+bug2_FS+bug3_FS+bug4_FS);
    emit Bug_DCDL(bug1_DCDL+bug2_DCDL+bug3_DCDL+bug4_DCDL);
    emit Bug_DCGW(bug1_DCGW+bug2_DCGW+bug3_DCGW+bug4_DCGW);
    emit Bug_DCSCGY(bug1_DCSCGY+bug2_DCSCGY+bug3_DCSCGY+bug4_DCSCGY);

}

void MainWindow::modView_state2(QString da)
{
    QString byte1 = QString("%1").arg(da.mid(0,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte1_0 = byte1.mid(0,1);//模块故障（红指示灯）
    QString byte1_1 = byte1.mid(1,1);//模块保护（黄指示灯）
    //QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//模块内部 SCI 通信故障
    QString byte1_4 = byte1.mid(4,1);//输入模式检测错误（或输入接线错误）
    QString byte1_5 = byte1.mid(5,1);//监控下发输入模式与实际工作模式不匹配
    //QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//DCDC 过压
    if(byte1_0 == "0"){
        ui->light_bug2->setGreen();
    }else if(byte1_0 == "1"){
        ui->light_bug2->setRed();
    }
    if(byte1_1 == "0"){
        ui->light_pro2->setGreen();
    }else if(byte1_1 == "1"){
        ui->light_pro2->setYellow();
    }
    if(byte1_3 == "0"){
        bug2_SCI = 0;
    }else if(byte1_3 == "1"){
        bug2_SCI = 1;
    }
    if(byte1_4 == "0"){
        bug2_JX = 0;
    }else if(byte1_4 == "1"){
        bug2_JX = 1;
    }
    if(byte1_5 == "0"){
        bug2_ModBug = 0;
    }else if(byte1_5 == "1"){
        bug2_ModBug = 1;
    }
    if(byte1_7 == "0"){
        bug2_DCGY = 0;
    }else if(byte1_7 == "1"){
        bug2_DCGY = 1;
    }
    emit Bug_SCI(bug1_SCI+bug2_SCI+bug3_SCI+bug4_SCI);
    emit Bug_JX(bug1_JX+bug2_JX+bug3_JX+bug4_JX);
    emit Bug_ModBug(bug1_ModBug+bug2_ModBug+bug3_ModBug+bug4_ModBug);
    emit Bug_DCGY(bug1_DCGY+bug2_DCGY+bug3_DCGY+bug4_DCGY);

    QString byte2 = QString("%1").arg(da.mid(2,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte2_0 = byte2.mid(0,1);//PFC电压异常（不平衡或过压或欠压）
    QString byte2_1 = byte2.mid(1,1);//交流过压
    //QString byte2_2 = byte2.mid(2,1);//输出过压告警
    //QString byte2_3 = byte2.mid(3,1);//过温告警
    //QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    //QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//交流欠压
    //QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态
    if(byte2_0 == "0"){
        bug2_PFC = 0;
    }else if(byte2_0 == "1"){
        bug2_PFC = 1;
    }
    if(byte2_1 == "0"){
        bug2_JLGY = 0;
    }else if(byte2_1 == "1"){
        bug2_JLGY = 1;
    }
    if(byte2_6 == "0"){
        bug2_JLQY = 0;
    }else if(byte2_6 == "1"){
        bug2_JLQY = 1;
    }
    emit Bug_PFC(bug1_PFC+bug2_PFC+bug3_PFC+bug4_PFC);
    emit Bug_JLGY(bug1_JLGY+bug2_JLGY+bug3_JLGY+bug4_JLGY);
    emit Bug_JLQY(bug1_JLQY+bug2_JLQY+bug3_JLQY+bug4_JLQY);

    QString byte3 = QString("%1").arg(da.mid(4,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte3_0 = byte3.mid(0,1);//CAN通信故障
    QString byte3_1 = byte3.mid(1,1);//模块不均流
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    //QString byte3_3 = byte3.mid(3,1);//模块休眠
    //QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    //QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_6 = byte3.mid(5,1);//DCDC开关机状态 0：开机，1：关机
    QString byte3_7 = byte3.mid(7,1);//模块限功率
    if(byte3_0 == "0"){
        bug2_CAN = 0;
    }else if(byte3_0 == "1"){
        bug2_CAN = 1;
    }
    if(byte3_1 == "0"){
        bug2_BJL = 0;
    }else if(byte3_1 == "1"){
        bug2_BJL = 1;
    }
    if(byte3_6 == "0"){
        ui->light_start2->setGreen();
    }else if(byte3_6 == "1"){
        ui->light_start2->setRed();
    }
    if(byte3_7 == "0"){
        ui->light_w2->setGray();
    }else if(byte3_7 == "1"){
        ui->light_w2->setYellow();
    }
    emit Bug_CAN(bug1_CAN+bug2_CAN+bug3_CAN+bug4_CAN);
    emit Bug_BJL(bug1_BJL+bug2_BJL+bug3_BJL+bug4_BJL);

    QString byte4 = QString("%1").arg(da.mid(6,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte4_0 = byte3.mid(0,1);//温度限功率
    QString byte4_1 = byte3.mid(1,1);//交流限功率
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte4_3 = byte3.mid(3,1);//风扇故障
    QString byte4_4 = byte3.mid(4,1);//DCDC短路
    //QString byte4_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte4_6 = byte3.mid(5,1);//DCDC过温
    QString byte4_7 = byte3.mid(7,1);//DCDC输出过压
    if(byte4_0 == "0"){
        ui->light_tem2->setGray();
    }else if(byte4_0 == "1"){
        ui->light_tem2->setYellow();
    }
    if(byte4_1 == "0"){
        ui->light_cur2->setGray();
    }else if(byte4_1 == "1"){
        ui->light_cur2->setYellow();
    }
    if(byte4_3 == "0"){
        bug2_FS = 0;
    }else if(byte4_3 == "1"){
        bug2_FS = 1;
    }
    if(byte4_4 == "0"){
        bug2_DCDL = 0;
    }else if(byte4_4 == "1"){
        bug2_DCDL = 1;
    }
    if(byte4_6 == "0"){
        bug2_DCGW = 0;
    }else if(byte4_6 == "1"){
        bug2_DCGW = 1;
    }
    if(byte4_7 == "0"){
        bug2_DCSCGY = 0;
    }else if(byte4_7 == "1"){
        bug2_DCSCGY = 1;
    }
    emit Bug_FS(bug1_FS+bug2_FS+bug3_FS+bug4_FS);
    emit Bug_DCDL(bug1_DCDL+bug2_DCDL+bug3_DCDL+bug4_DCDL);
    emit Bug_DCGW(bug1_DCGW+bug2_DCGW+bug3_DCGW+bug4_DCGW);
    emit Bug_DCSCGY(bug1_DCSCGY+bug2_DCSCGY+bug3_DCSCGY+bug4_DCSCGY);
}

void MainWindow::modView_state3(QString da)
{
    QString byte1 = QString("%1").arg(da.mid(0,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte1_0 = byte1.mid(0,1);//模块故障（红指示灯）
    QString byte1_1 = byte1.mid(1,1);//模块保护（黄指示灯）
    //QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//模块内部 SCI 通信故障
    QString byte1_4 = byte1.mid(4,1);//输入模式检测错误（或输入接线错误）
    QString byte1_5 = byte1.mid(5,1);//监控下发输入模式与实际工作模式不匹配
    //QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//DCDC 过压
    if(byte1_0 == "0"){
        ui->light_bug3->setGreen();
    }else if(byte1_0 == "1"){
        ui->light_bug3->setRed();
    }
    if(byte1_1 == "0"){
        ui->light_pro3->setGreen();
    }else if(byte1_1 == "1"){
        ui->light_pro3->setYellow();
    }
    if(byte1_3 == "0"){
        bug3_SCI = 0;
    }else if(byte1_3 == "1"){
        bug3_SCI = 1;
    }
    if(byte1_4 == "0"){
        bug3_JX = 0;
    }else if(byte1_4 == "1"){
        bug3_JX = 1;
    }
    if(byte1_5 == "0"){
        bug3_ModBug = 0;
    }else if(byte1_5 == "1"){
        bug3_ModBug = 1;
    }
    if(byte1_7 == "0"){
        bug3_DCGY = 0;
    }else if(byte1_7 == "1"){
        bug3_DCGY = 1;
    }
    emit Bug_SCI(bug1_SCI+bug2_SCI+bug3_SCI+bug4_SCI);
    emit Bug_JX(bug1_JX+bug2_JX+bug3_JX+bug4_JX);
    emit Bug_ModBug(bug1_ModBug+bug2_ModBug+bug3_ModBug+bug4_ModBug);
    emit Bug_DCGY(bug1_DCGY+bug2_DCGY+bug3_DCGY+bug4_DCGY);

    QString byte2 = QString("%1").arg(da.mid(2,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte2_0 = byte2.mid(0,1);//PFC电压异常（不平衡或过压或欠压）
    QString byte2_1 = byte2.mid(1,1);//交流过压
    //QString byte2_2 = byte2.mid(2,1);//输出过压告警
    //QString byte2_3 = byte2.mid(3,1);//过温告警
    //QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    //QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//交流欠压
    //QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态
    if(byte2_0 == "0"){
        bug3_PFC = 0;
    }else if(byte2_0 == "1"){
        bug3_PFC = 1;
    }
    if(byte2_1 == "0"){
        bug3_JLGY = 0;
    }else if(byte2_1 == "1"){
        bug3_JLGY = 1;
    }
    if(byte2_6 == "0"){
        bug3_JLQY = 0;
    }else if(byte2_6 == "1"){
        bug3_JLQY = 1;
    }
    emit Bug_PFC(bug1_PFC+bug2_PFC+bug3_PFC+bug4_PFC);
    emit Bug_JLGY(bug1_JLGY+bug2_JLGY+bug3_JLGY+bug4_JLGY);
    emit Bug_JLQY(bug1_JLQY+bug2_JLQY+bug3_JLQY+bug4_JLQY);

    QString byte3 = QString("%1").arg(da.mid(4,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte3_0 = byte3.mid(0,1);//CAN通信故障
    QString byte3_1 = byte3.mid(1,1);//模块不均流
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    //QString byte3_3 = byte3.mid(3,1);//模块休眠
    //QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    //QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_6 = byte3.mid(5,1);//DCDC开关机状态 0：开机，1：关机
    QString byte3_7 = byte3.mid(7,1);//模块限功率
    if(byte3_0 == "0"){
        bug3_CAN = 0;
    }else if(byte3_0 == "1"){
        bug3_CAN = 1;
    }
    if(byte3_1 == "0"){
        bug3_BJL = 0;
    }else if(byte3_1 == "1"){
        bug3_BJL = 1;
    }
    if(byte3_6 == "0"){
        ui->light_start3->setGreen();
    }else if(byte3_6 == "1"){
        ui->light_start3->setRed();
    }
    if(byte3_7 == "0"){
        ui->light_w3->setGray();
    }else if(byte3_7 == "1"){
        ui->light_w3->setYellow();
    }
    emit Bug_CAN(bug1_CAN+bug2_CAN+bug3_CAN+bug4_CAN);
    emit Bug_BJL(bug1_BJL+bug2_BJL+bug3_BJL+bug4_BJL);

    QString byte4 = QString("%1").arg(da.mid(6,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte4_0 = byte3.mid(0,1);//温度限功率
    QString byte4_1 = byte3.mid(1,1);//交流限功率
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte4_3 = byte3.mid(3,1);//风扇故障
    QString byte4_4 = byte3.mid(4,1);//DCDC短路
    //QString byte4_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte4_6 = byte3.mid(5,1);//DCDC过温
    QString byte4_7 = byte3.mid(7,1);//DCDC输出过压
    if(byte4_0 == "0"){
        ui->light_tem3->setGray();
    }else if(byte4_0 == "1"){
        ui->light_tem3->setYellow();
    }
    if(byte4_1 == "0"){
        ui->light_cur3->setGray();
    }else if(byte4_1 == "1"){
        ui->light_cur3->setYellow();
    }
    if(byte4_3 == "0"){
        bug3_FS = 0;
    }else if(byte4_3 == "1"){
        bug3_FS = 1;
    }
    if(byte4_4 == "0"){
        bug3_DCDL = 0;
    }else if(byte4_4 == "1"){
        bug3_DCDL = 1;
    }
    if(byte4_6 == "0"){
        bug3_DCGW = 0;
    }else if(byte4_6 == "1"){
        bug3_DCGW = 1;
    }
    if(byte4_7 == "0"){
        bug3_DCSCGY = 0;
    }else if(byte4_7 == "1"){
        bug3_DCSCGY = 1;
    }
    emit Bug_FS(bug1_FS+bug2_FS+bug3_FS+bug4_FS);
    emit Bug_DCDL(bug1_DCDL+bug2_DCDL+bug3_DCDL+bug4_DCDL);
    emit Bug_DCGW(bug1_DCGW+bug2_DCGW+bug3_DCGW+bug4_DCGW);
    emit Bug_DCSCGY(bug1_DCSCGY+bug2_DCSCGY+bug3_DCSCGY+bug4_DCSCGY);
}

void MainWindow::modView_state4(QString da)
{
    QString byte1 = QString("%1").arg(da.mid(0,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte1_0 = byte1.mid(0,1);//模块故障（红指示灯）
    QString byte1_1 = byte1.mid(1,1);//模块保护（黄指示灯）
    //QString byte1_2 = byte1.mid(2,1);//输入欠压告警
    QString byte1_3 = byte1.mid(3,1);//模块内部 SCI 通信故障
    QString byte1_4 = byte1.mid(4,1);//输入模式检测错误（或输入接线错误）
    QString byte1_5 = byte1.mid(5,1);//监控下发输入模式与实际工作模式不匹配
    //QString byte1_6 = byte1.mid(6,1);//模块 ID 重复
    QString byte1_7 = byte1.mid(7,1);//DCDC 过压
    if(byte1_0 == "0"){
        ui->light_bug4->setGreen();
    }else if(byte1_0 == "1"){
        ui->light_bug4->setRed();
    }
    if(byte1_1 == "0"){
        ui->light_pro4->setGreen();
    }else if(byte1_1 == "1"){
        ui->light_pro4->setYellow();
    }
    if(byte1_3 == "0"){
        bug4_SCI = 0;
    }else if(byte1_3 == "1"){
        bug4_SCI = 1;
    }
    if(byte1_4 == "0"){
        bug4_JX = 0;
    }else if(byte1_4 == "1"){
        bug4_JX = 1;
    }
    if(byte1_5 == "0"){
        bug4_ModBug = 0;
    }else if(byte1_5 == "1"){
        bug4_ModBug = 1;
    }
    if(byte1_7 == "0"){
        bug4_DCGY = 0;
    }else if(byte1_7 == "1"){
        bug4_DCGY = 1;
    }
    emit Bug_SCI(bug1_SCI+bug2_SCI+bug3_SCI+bug4_SCI);
    emit Bug_JX(bug1_JX+bug2_JX+bug3_JX+bug4_JX);
    emit Bug_ModBug(bug1_ModBug+bug2_ModBug+bug3_ModBug+bug4_ModBug);
    emit Bug_DCGY(bug1_DCGY+bug2_DCGY+bug3_DCGY+bug4_DCGY);

    QString byte2 = QString("%1").arg(da.mid(2,2).toInt(0,16), 8, 2, QLatin1Char('0'));
    QString byte2_0 = byte2.mid(0,1);//PFC电压异常（不平衡或过压或欠压）
    QString byte2_1 = byte2.mid(1,1);//交流过压
    //QString byte2_2 = byte2.mid(2,1);//输出过压告警
    //QString byte2_3 = byte2.mid(3,1);//过温告警
    //QString byte2_4 = byte2.mid(4,1);//风扇故障告警
    //QString byte2_5 = byte2.mid(5,1);//模块保护告警
    QString byte2_6 = byte2.mid(6,1);//交流欠压
    //QString byte2_7 = byte2.mid(7,1);//模块 DC 侧处于关机状态
    if(byte2_0 == "0"){
        bug4_PFC = 0;
    }else if(byte2_0 == "1"){
        bug4_PFC = 1;
    }
    if(byte2_1 == "0"){
        bug4_JLGY = 0;
    }else if(byte2_1 == "1"){
        bug4_JLGY = 1;
    }
    if(byte2_6 == "0"){
        bug4_JLQY = 0;
    }else if(byte2_6 == "1"){
        bug4_JLQY = 1;
    }
    emit Bug_PFC(bug1_PFC+bug2_PFC+bug3_PFC+bug4_PFC);
    emit Bug_JLGY(bug1_JLGY+bug2_JLGY+bug3_JLGY+bug4_JLGY);
    emit Bug_JLQY(bug1_JLQY+bug2_JLQY+bug3_JLQY+bug4_JLQY);

    QString byte3 = QString("%1").arg(da.mid(4,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte3_0 = byte3.mid(0,1);//CAN通信故障
    QString byte3_1 = byte3.mid(1,1);//模块不均流
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    //QString byte3_3 = byte3.mid(3,1);//模块休眠
    //QString byte3_4 = byte3.mid(4,1);//输入或母线异常
    //QString byte3_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte3_6 = byte3.mid(5,1);//DCDC开关机状态 0：开机，1：关机
    QString byte3_7 = byte3.mid(7,1);//模块限功率
    if(byte3_0 == "0"){
        bug4_CAN = 0;
    }else if(byte3_0 == "1"){
        bug4_CAN = 1;
    }
    if(byte3_1 == "0"){
        bug4_BJL = 0;
    }else if(byte3_1 == "1"){
        bug4_BJL = 1;
    }
    if(byte3_6 == "0"){
        ui->light_start4->setGreen();
    }else if(byte3_6 == "1"){
        ui->light_start4->setRed();
    }
    if(byte3_7 == "0"){
        ui->light_w4->setGray();
    }else if(byte3_7 == "1"){
        ui->light_w4->setYellow();
    }
    emit Bug_CAN(bug1_CAN+bug2_CAN+bug3_CAN+bug4_CAN);
    emit Bug_BJL(bug1_BJL+bug2_BJL+bug3_BJL+bug4_BJL);

    QString byte4 = QString("%1").arg(da.mid(6,2).toInt(0,16), 8, 2, QLatin1Char('0'));//状态0
    QString byte4_0 = byte3.mid(0,1);//温度限功率
    QString byte4_1 = byte3.mid(1,1);//交流限功率
    //QString byte3_2 = byte3.mid(2,1);//模块放电异常
    QString byte4_3 = byte3.mid(3,1);//风扇故障
    QString byte4_4 = byte3.mid(4,1);//DCDC短路
    //QString byte4_5 = byte3.mid(5,1);//模块内部通信故障
    QString byte4_6 = byte3.mid(5,1);//DCDC过温
    QString byte4_7 = byte3.mid(7,1);//DCDC输出过压
    if(byte4_0 == "0"){
        ui->light_tem4->setGray();
    }else if(byte4_0 == "1"){
        ui->light_tem4->setYellow();
    }
    if(byte4_1 == "0"){
        ui->light_cur4->setGray();
    }else if(byte4_1 == "1"){
        ui->light_cur4->setYellow();
    }
    if(byte4_3 == "0"){
        bug4_FS = 0;
    }else if(byte4_3 == "1"){
        bug4_FS = 1;
    }
    if(byte4_4 == "0"){
        bug4_DCDL = 0;
    }else if(byte4_4 == "1"){
        bug4_DCDL = 1;
    }
    if(byte4_6 == "0"){
        bug4_DCGW = 0;
    }else if(byte4_6 == "1"){
        bug4_DCGW = 1;
    }
    if(byte4_7 == "0"){
        bug4_DCSCGY = 0;
    }else if(byte4_7 == "1"){
        bug4_DCSCGY = 1;
    }
    emit Bug_FS(bug1_FS+bug2_FS+bug3_FS+bug4_FS);
    emit Bug_DCDL(bug1_DCDL+bug2_DCDL+bug3_DCDL+bug4_DCDL);
    emit Bug_DCGW(bug1_DCGW+bug2_DCGW+bug3_DCGW+bug4_DCGW);
    emit Bug_DCSCGY(bug1_DCSCGY+bug2_DCSCGY+bug3_DCSCGY+bug4_DCSCGY);
}

void MainWindow::modView_w1(QString da)
{
    int vol = da.toUInt(nullptr, 16);
    W1 = *(float*)&vol;
    //qDebug()<<V2;
    if(W1 == 20000){
        ui->lineEdit_mol->setText("20KW");
    }else if(W1 == 40000)
    {
        ui->lineEdit_mol->setText("40KW");
    }
    //ui->lineEdit_mol->setText(QString::number(W1));
}

void MainWindow::modView_w2(QString da)
{
    int vol = da.toUInt(nullptr, 16);
    W2 = *(float*)&vol;
    if(W2 == 20000){
        ui->lineEdit_mol->setText("20KW");
    }else if(W2 == 40000)
    {
        ui->lineEdit_mol->setText("40KW");
    }
}

void MainWindow::modView_w3(QString da)
{
    int vol = da.toUInt(nullptr, 16);
    W3 = *(float*)&vol;
    if(W3 == 20000){
        ui->lineEdit_mol->setText("20KW");
    }else if(W3 == 40000)
    {
        ui->lineEdit_mol->setText("40KW");
    }
}

void MainWindow::modView_w4(QString da)
{
    int vol = da.toUInt(nullptr, 16);
    W4 = *(float*)&vol;
    if(W4 == 20000){
        ui->lineEdit_mol->setText("20KW");
    }else if(W4 == 40000)
    {
        ui->lineEdit_mol->setText("40KW");
    }
}

void MainWindow::BugView_SCI(int bug)
{
    if(bug == 0){
        ui->pushButton_sci->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_sci->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_JX(int bug)
{
    if(bug == 0){
        ui->pushButton_jxbug->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_jxbug->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_ModBug(int bug)
{
    if(bug == 0){
        ui->pushButton_modbug->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_modbug->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_DCGY(int bug)
{
    if(bug == 0){
        ui->pushButton_dcgy->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_dcgy->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_PFC(int bug)
{
    if(bug == 0){
        ui->pushButton_pfc->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_pfc->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_JLGY(int bug)
{
    if(bug == 0){
        ui->pushButton_jlgy->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_jlgy->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_JLQY(int bug)
{
    if(bug == 0){
        ui->pushButton_jlqy->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_jlqy->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_CAN(int bug)
{
    if(bug == 0){
        ui->pushButton_canbug->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_canbug->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_BJL(int bug)
{
    if(bug == 0){
        ui->pushButton_bjl->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_bjl->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_FS(int bug)
{
    if(bug == 0){
        ui->pushButton_fsbug->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_fsbug->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_DCDL(int bug)
{
    if(bug == 0){
        ui->pushButton_dcdl->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_dcdl->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_DCGW(int bug)
{
    if(bug == 0){
        ui->pushButton_dcgw->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_dcgw->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

void MainWindow::BugView_DCSCGY(int bug)
{
    if(bug == 0){
        ui->pushButton_dcsc->setStyleSheet("background-color: rgb(0, 255, 0);");
    }else if(bug != 0){
        ui->pushButton_dcsc->setStyleSheet("background-color: rgb(255, 0, 0);");
    }
}

//CAN自动打开
void MainWindow::on_btnCan_clicked()
{
    emit SIGtocancon();
}

void MainWindow::on_btn_start_clicked()
{
    QMessageBox::StandardButton box;
    box = QMessageBox::question(this, "提示", "是否确定开机", QMessageBox::Yes|QMessageBox::No);
    //取消
    if(box==QMessageBox::No)
        return;
    //确认
    else if(box==QMessageBox::Yes)
    {
        //qDebug()<<"exit null score";
        int ID;
        ID = 0x0607FF80;
        QString Data = "0300003000000000";
        std::vector<int> vec;
        QByteArray data1 = Data.toUpper().toLatin1();
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
}


void MainWindow::on_btn_stop_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300003000010000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);

    QMessageBox msgbox;
    msgbox.setText("已关机");
    msgbox.setIcon(QMessageBox::Information);
    msgbox.setWindowTitle("提示");
    QTimer::singleShot(3000, &msgbox, &QMessageBox::close);
    msgbox.exec();
}


void MainWindow::on_btn_setV_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString da = "03000021";
    float daV = ui->lineEdit_setV->text().toFloat();
    uint f_uint = *(uint*)&daV;
    QString strV = QString("%1").arg(f_uint, 8, 16, QLatin1Char('0'));	// 4是生成字符串的最小长度，可以改为8
    //qDebug() << f_hex;	// "41a29168"
    QString Data = da+strV;
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::on_btn_setA_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString da = "03000022";
    float daA = ui->lineEdit_setA->text().toFloat()/100;
    uint f_uint = *(uint*)&daA;
    QString strA = QString("%1").arg(f_uint, 8, 16, QLatin1Char('0'));	// 4是生成字符串的最小长度，可以改为8
    //qDebug() << strA;	// "41a29168"
    QString Data = da+strA;
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

//游标槽函数
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    QCPGraph *mGraph = plot->graph();
    //曲线数量
    int graphCount=8;
    //获得鼠标位置处对应的横坐标数据x
    double x = plot->xAxis->pixelToCoord(event->pos().x());
    //遍历曲线
    for (int i = 0; i < graphCount; ++i)
    {
        //判断哪一条曲线被选中
        if(plot->graph(i)->selected())
        {
            //显示锚点
            tracer->setVisible(true);
            mGraph = plot->graph(i);

            tracer->setGraph(mGraph);//将锚点设置到被选中的曲线上
            //将像素点转换成qcustomplot中的坐标值，并通过setGraphKey将锚点值设为真实数据值。tracer->setGraphKey(xAxis->pixelToCoord(event->pos().x()));
            tracer->setGraphKey(x); //将游标横坐标设置成刚获得的横坐标数据x
            tracer->setInterpolating(true); //游标的纵坐标可以通过曲线数据线性插值自动获得
            tracer->updatePosition(); //使得刚设置游标的横纵坐标位置生效
            double xValue = tracer->position->key();
            double yValue = tracer->position->value();
            //显示tip框
            QToolTip::showText(event->globalPos(), tr(
                                   "<h4>%1</h4>"
                                   "<table>"
                                   "<tr>"
                                   "<td><h5>时间: %2</h5></td>" "<td> , </td>" "<td><h5>Value: %3</h5></td>"
                                   "</tr>"
                                   "</table>").arg(mGraph->name()).arg(QDateTime::fromMSecsSinceEpoch(xValue*1000.0).toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(QString::number(yValue,'f',2)), this, this->rect());
            break;
        }
        else
        {
            //没有曲线被选中，不显示锚点
            tracer->setVisible(false);
        }
    }
    //重绘
    plot->replot();
}


//图例选中图像槽函数
void MainWindow::selectionChanged()
{
    // synchronize selection of graphs with selection of corresponding legend items:
    for (int i=0; i<plot->graphCount(); ++i)
    {
        QCPGraph *graph = plot->graph(i);
        QCPPlottableLegendItem *item = plot->legend->itemWithPlottable(graph);

        if (item->selected())
        {
            item->setSelected(true);
            graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
        }
        plot->update();
    }
}


void MainWindow::on_comboBox_all_currentIndexChanged(int index)
{
    if(index == 1)
    {
        ui->stackedWidget->setCurrentIndex(1);
    }
    else{
        ui->stackedWidget->setCurrentIndex(0);
    }
    //qDebug()<<index;
}


void MainWindow::on_btnCAN_clicked()
{
    emit SIGtocancon();
}

//过压复位
void MainWindow::on_btn_res_4_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300003100010000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

//短路复位
void MainWindow::on_btn_res_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300004400010000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::on_btn_start_2_clicked()
{
    QMessageBox::StandardButton box;
    box = QMessageBox::question(this, "提示", "是否确定开机", QMessageBox::Yes|QMessageBox::No);
    //取消
    if(box==QMessageBox::No)
        return;
    //确认
    else if(box==QMessageBox::Yes)
    {
        //qDebug()<<"exit null score";
        int ID;
        ID = 0x0607FF80;
        QString Data = "0300003000000000";
        std::vector<int> vec;
        QByteArray data1 = Data.toUpper().toLatin1();
        for(int i=0; i<8; i++)
        {
            vec.push_back(Data.mid(2*i,2).toInt(0,16));
            double vec = QRandomGenerator::global()->generateDouble();
        }
        emit SIGtocansen(ID,vec);
    }
}


void MainWindow::on_btn_stop_2_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300003000010000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);    
}

//40KW过压复位
void MainWindow::on_btn_res_2_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300003100010000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

//40KW短路复位
void MainWindow::on_btn_res_3_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString Data = "0300004400010000";
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::on_btn_setV_2_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString da = "03000021";
    float daV = ui->lineEdit_setV_2->text().toFloat();
    uint f_uint = *(uint*)&daV;
    QString strV = QString("%1").arg(f_uint, 8, 16, QLatin1Char('0'));	// 4是生成字符串的最小长度，可以改为8
    //qDebug() << f_hex;	// "41a29168"
    QString Data = da+strV;
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}


void MainWindow::on_btn_setA_2_clicked()
{
    int ID;
    ID = 0x0607FF80;
    QString da = "03000022";
    float daA = ui->lineEdit_setA_2->text().toFloat()/100;
    uint f_uint = *(uint*)&daA;
    QString strA = QString("%1").arg(f_uint, 8, 16, QLatin1Char('0'));	// 4是生成字符串的最小长度，可以改为8
    //qDebug() << strA;	// "41a29168"
    QString Data = da+strA;
    std::vector<int> vec;
    QByteArray data1 = Data.toUpper().toLatin1();
    for(int i=0; i<8; i++)
    {
        vec.push_back(Data.mid(2*i,2).toInt(0,16));
        double vec = QRandomGenerator::global()->generateDouble();
    }
    emit SIGtocansen(ID,vec);
}

